#include <iostream>
using namespace std;
/*
Create three classes.
The first class contains private data,
and grants friendship to the entire second class and to a member function of the third class.
In main( ), demonstrate that all of these work correctly.
*/

// 前置声明
class C1;
class C2;
class C3;

class C3
{
public:
    C1 *p;
    void function3();
};

class C1
{
    friend class C2;
    friend void C3::function3();

public:
    int data;
};

class C2
{
public:
    C1 *p;
    C2();
};

void C3::function3()
{
    p = new C1;
    p->data = 100;
    cout << "the function in C3 can call the private data in C1. "
         << "data = " << p->data << endl;
}

C2::C2()
{
    p = new C1;
    p->data = 99;
    cout << "class C2 can call the private data in C1. "
         << "data = " << p->data << endl;
}

int main()
{
    C3 c3;
    c3.function3();

    C2 c2;

    return 0;
}